package com.wc.AlgoOJ_homework.AlgoOJ_BL2.B_工作时长;

import java.io.*;
import java.util.*;

/**
 * @Author congge
 * @Date 2024/4/1 18:47
 * @description http://43.138.190.70:8888/p/1077?tid=6602a6e518e03a818a4bf047
 */
public class Main {
    public static void main(String[] args) throws IOException {
        File f = new File("src/com/wc/AlgoOJ_homework/AlgoOJ_BL2/B_工作时长/time.txt");
        BufferedReader br = new BufferedReader(new FileReader(f));
        String line;
        ArrayList<String> lines = new ArrayList<>();
        while ((line = br.readLine()) != null) {
            lines.add(line);
        }
        lines.sort(Comparator.comparing(Objects::toString));
        long res = 0;
        for (int i = 0; i < lines.size(); i += 2) {
            String start = lines.get(i);
            String end = lines.get(i + 1);
            res += cal(start, end);
        }
        System.out.println(res);
    }

    static int cal(String start, String end) {
        String[] ss = start.split(" ");
        String[] ee = end.split(" ");
        int res = 0;
        if (ss[0].equals(ee[0])) {
            String[] em = ee[1].split(":");
            String[] sm = ss[1].split(":");
            return cal(em) - cal(sm);
        } else {
            System.out.println("________________________");
        }
        return 0;
    }

    static int cal(String[] ss) {
        int h = Integer.parseInt(ss[0]);
        int m = Integer.parseInt(ss[1]);
        int s = Integer.parseInt(ss[2]);
        return h * 3600 + m * 60 + s;
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
